<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [
      {
        name: '张三',
        salary: 10000
      },
      {
        name: '李四',
        salary: 10000
      },
      {
        name: '王五',
        salary: 10000
      }
    ]
    // 计算薪资案例
    // const toal = arr.reduce((prev, current) => prev + current.salary)  // [object Object]1000010000
    // 遇到对象数组一定要设置起始值，不然以第一个元素为起始值就是上面那种情况
    const toal = arr.reduce((prev, current) => prev + current.salary, 0)
    console.log(toal)  // 30000

    // 需求：每个人涨薪30%
    const total = arr.reduce((prev, current) => prev + current.salary * 1.3, 0)
    console.log(total)  // 39000
  </script>
</body>

</html>